<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="部门" prop="eDname">
      <el-input v-model="dataForm.eDname" placeholder="部门"></el-input>
    </el-form-item>
    <el-form-item label="员工姓名" prop="eMname">
      <el-input v-model="dataForm.eMname" placeholder="员工姓名"></el-input>
    </el-form-item>
    <el-form-item label="员工工号" prop="eMid">
      <el-input v-model="dataForm.eMid" placeholder="员工工号"></el-input>
    </el-form-item>
    <el-form-item label="岗位名称" prop="eGname">
      <el-input v-model="dataForm.eGname" placeholder="岗位名称"></el-input>
    </el-form-item>
    <el-form-item label="岗位职责" prop="eGduty">
      <el-input v-model="dataForm.eGduty" placeholder="岗位职责"></el-input>
    </el-form-item>
    <el-form-item label="性别" prop="eMsex">
      <el-input v-model="dataForm.eMsex" placeholder="性别"></el-input>
    </el-form-item>
    <el-form-item label="工作电话" prop="eWphone">
      <el-input v-model="dataForm.eWphone" placeholder="工作电话"></el-input>
    </el-form-item>
    <el-form-item label="手机号码" prop="eMphone">
      <el-input v-model="dataForm.eMphone" placeholder="手机号码"></el-input>
    </el-form-item>
    <el-form-item label="邮箱" prop="eMmail">
      <el-input v-model="dataForm.eMmail" placeholder="邮箱"></el-input>
    </el-form-item>
    <el-form-item label="工作QQ" prop="eMqq">
      <el-input v-model="dataForm.eMqq" placeholder="工作QQ"></el-input>
    </el-form-item>
    <el-form-item label="短号" prop="eMshortnumber">
      <el-input v-model="dataForm.eMshortnumber" placeholder="短号"></el-input>
    </el-form-item>
    <el-form-item label="职位级别" prop="ePositionlevel">
      <el-input v-model="dataForm.ePositionlevel" placeholder="职位级别"></el-input>
    </el-form-item>
    <el-form-item label="职务类别" prop="ePositontype">
      <el-input v-model="dataForm.ePositontype" placeholder="职务类别"></el-input>
    </el-form-item>
    <el-form-item label="员工状态" prop="eMstatus">
      <el-input v-model="dataForm.eMstatus" placeholder="员工状态"></el-input>
    </el-form-item>
    <el-form-item label="是否离职" prop="eMquit">
      <el-input v-model="dataForm.eMquit" placeholder="是否离职"></el-input>
    </el-form-item>
    <el-form-item label="分配状态" prop="eAllocation">
      <el-input v-model="dataForm.eAllocation" placeholder="分配状态"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="eRemarks">
      <el-input v-model="dataForm.eRemarks" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="创建日期" prop="eDate">
      <el-input v-model="dataForm.eDate" placeholder="创建日期"></el-input>
    </el-form-item>
    <el-form-item label="分包状态" prop="eFstatus">
      <el-input v-model="dataForm.eFstatus" placeholder="分包状态"></el-input>
    </el-form-item>
    <el-form-item label="员工所在部门id" prop="eDeptid">
      <el-input v-model="dataForm.eDeptid" placeholder="员工所在部门id"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          eId: 0,
          eDname: '',
          eMname: '',
          eMid: '',
          eGname: '',
          eGduty: '',
          eMsex: '',
          eWphone: '',
          eMphone: '',
          eMmail: '',
          eMqq: '',
          eMshortnumber: '',
          ePositionlevel: '',
          ePositontype: '',
          eMstatus: '',
          eMquit: '',
          eAllocation: '',
          eRemarks: '',
          eDate: '',
          eFstatus: '',
          eDeptid: ''
        },
        dataRule: {
          eDname: [
            { required: true, message: '部门不能为空', trigger: 'blur' }
          ],
          eMname: [
            { required: true, message: '员工姓名不能为空', trigger: 'blur' }
          ],
          eMid: [
            { required: true, message: '员工工号不能为空', trigger: 'blur' }
          ],
          eGname: [
            { required: true, message: '岗位名称不能为空', trigger: 'blur' }
          ],
          eGduty: [
            { required: true, message: '岗位职责不能为空', trigger: 'blur' }
          ],
          eMsex: [
            { required: true, message: '性别不能为空', trigger: 'blur' }
          ],
          eWphone: [
            { required: true, message: '工作电话不能为空', trigger: 'blur' }
          ],
          eMphone: [
            { required: true, message: '手机号码不能为空', trigger: 'blur' }
          ],
          eMmail: [
            { required: true, message: '邮箱不能为空', trigger: 'blur' }
          ],
          eMqq: [
            { required: true, message: '工作QQ不能为空', trigger: 'blur' }
          ],
          eMshortnumber: [
            { required: true, message: '短号不能为空', trigger: 'blur' }
          ],
          ePositionlevel: [
            { required: true, message: '职位级别不能为空', trigger: 'blur' }
          ],
          ePositontype: [
            { required: true, message: '职务类别不能为空', trigger: 'blur' }
          ],
          eMstatus: [
            { required: true, message: '员工状态不能为空', trigger: 'blur' }
          ],
          eMquit: [
            { required: true, message: '是否离职不能为空', trigger: 'blur' }
          ],
          eAllocation: [
            { required: true, message: '分配状态不能为空', trigger: 'blur' }
          ],
          eRemarks: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          eDate: [
            { required: true, message: '创建日期不能为空', trigger: 'blur' }
          ],
          eFstatus: [
            { required: true, message: '分包状态不能为空', trigger: 'blur' }
          ],
          eDeptid: [
            { required: true, message: '员工所在部门id不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.eId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.eId) {
            this.$http({
              url: this.$http.adornUrl(`/com/employee/info/${this.dataForm.eId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.eDname = data.employee.eDname
                this.dataForm.eMname = data.employee.eMname
                this.dataForm.eMid = data.employee.eMid
                this.dataForm.eGname = data.employee.eGname
                this.dataForm.eGduty = data.employee.eGduty
                this.dataForm.eMsex = data.employee.eMsex
                this.dataForm.eWphone = data.employee.eWphone
                this.dataForm.eMphone = data.employee.eMphone
                this.dataForm.eMmail = data.employee.eMmail
                this.dataForm.eMqq = data.employee.eMqq
                this.dataForm.eMshortnumber = data.employee.eMshortnumber
                this.dataForm.ePositionlevel = data.employee.ePositionlevel
                this.dataForm.ePositontype = data.employee.ePositontype
                this.dataForm.eMstatus = data.employee.eMstatus
                this.dataForm.eMquit = data.employee.eMquit
                this.dataForm.eAllocation = data.employee.eAllocation
                this.dataForm.eRemarks = data.employee.eRemarks
                this.dataForm.eDate = data.employee.eDate
                this.dataForm.eFstatus = data.employee.eFstatus
                this.dataForm.eDeptid = data.employee.eDeptid
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/com/employee/${!this.dataForm.eId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'eId': this.dataForm.eId || undefined,
                'eDname': this.dataForm.eDname,
                'eMname': this.dataForm.eMname,
                'eMid': this.dataForm.eMid,
                'eGname': this.dataForm.eGname,
                'eGduty': this.dataForm.eGduty,
                'eMsex': this.dataForm.eMsex,
                'eWphone': this.dataForm.eWphone,
                'eMphone': this.dataForm.eMphone,
                'eMmail': this.dataForm.eMmail,
                'eMqq': this.dataForm.eMqq,
                'eMshortnumber': this.dataForm.eMshortnumber,
                'ePositionlevel': this.dataForm.ePositionlevel,
                'ePositontype': this.dataForm.ePositontype,
                'eMstatus': this.dataForm.eMstatus,
                'eMquit': this.dataForm.eMquit,
                'eAllocation': this.dataForm.eAllocation,
                'eRemarks': this.dataForm.eRemarks,
                'eDate': this.dataForm.eDate,
                'eFstatus': this.dataForm.eFstatus,
                'eDeptid': this.dataForm.eDeptid
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
